home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Sample Code / AppsToGo / DTS.Draw / DoEvent.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-22  |  5.3 KB  |  209 lines  |  [TEXT/MPS ]

  1. /*
  2. ** Apple Macintosh Developer Technical Support
  3. **
  4. ** File:        DoEvent.c
  5. ** Written by:    Eric Soldan
  6. **
  7. ** Copyright © 1990-1993 Apple Computer, Inc.
  8. ** All rights reserved.
  9. */
  10.  
  11. /* You may incorporate this sample code into your applications without
  12. ** restriction, though the sample code has been provided "AS IS" and the
  13. ** responsibility for its operation is 100% yours.  However, what you are
  14. ** not permitted to do is to redistribute the source as "DSC Sample Code"
  15. ** after having made changes. If you're going to re-distribute the source,
  16. ** we require that you make it clear in the source that the code was
  17. ** descended from Apple Sample Code, but that you've made changes. */
  18.  
  19.  
  20.  
  21. /*****************************************************************************/
  22.  
  23.  
  24.  
  25. #include "App.h"            /* Get the application includes/typedefs, etc.    */
  26. #include "App.protos.h"        /* Get the prototypes for application.            */
  27.  
  28. #ifndef __CTLHANDLER__
  29. #include "CtlHandler.h"
  30. #endif
  31.  
  32. #ifndef __DESK__
  33. #include <Desk.h>
  34. #endif
  35.  
  36. #ifndef __DISKINIT__
  37. #include <DiskInit.h>
  38. #endif
  39.  
  40. #ifndef __ERRORS__
  41. #include <Errors.h>
  42. #endif
  43.  
  44. #ifndef __MENUS__
  45. #include <Menus.h>
  46. #endif
  47.  
  48. #ifndef __TEXTEDITCONTROL__
  49. #include "TextEditControl.h"
  50. #endif
  51.  
  52. #ifndef __TOOLUTILS__
  53. #include <ToolUtils.h>
  54. #endif
  55.  
  56. #ifndef __UTILITIES__
  57. #include "Utilities.h"
  58. #endif
  59.  
  60.  
  61.  
  62. /*****************************************************************************/
  63.  
  64.  
  65.  
  66. extern Cursor    *gCursorPtr;    /* See the file Window.c for comments about this global. */
  67.  
  68.  
  69.  
  70. /*****************************************************************************/
  71. /*****************************************************************************/
  72.  
  73. #ifdef applec
  74. #pragma segment DTSDrawSeg1
  75. #endif
  76.  
  77. /*****************************************************************************/
  78. /*****************************************************************************/
  79.  
  80.  
  81.  
  82. /* Do the right thing for an event.  Determine what kind of event it is, and
  83. ** call the appropriate routines. */
  84.  
  85. void    DoEvent(EventRecord *event)
  86. {
  87.     Point        pt;
  88.     OSErr        err;
  89.  
  90.     switch(event->what) {
  91.  
  92.         case nullEvent:
  93.             DoIdleTasks(event);
  94.             break;
  95.  
  96.         case mouseDown:
  97.             DoMouseDown(event);            /* Let framework handle mouse downs. */
  98.             break;
  99.  
  100.         case autoKey:
  101.         case keyDown:
  102.             DoKeyDown(event);            /* Let framework handle key events. */
  103.             break;
  104.  
  105.         case activateEvt:
  106.             gCursorPtr = nil;            /* Force recalculation of the cursor. */
  107.             DoActivate((WindowPtr)event->message);
  108.             break;
  109.  
  110.         case updateEvt:
  111.             DoUpdate((WindowPtr)event->message);
  112.             break;
  113.  
  114.         case kHighLevelEvent:
  115.             gCursorPtr = nil;            /* Force recalculation of the cursor. */
  116.             DoHighLevelEvent(event);
  117.             break;
  118.  
  119.         case osEvt:
  120.             gCursorPtr = nil;            /* Force recalculation of the cursor. */
  121.             switch ((event->message >> 24) & 0xFF) {
  122.                     /* Must logical and with 0xFF to get only low byte. */
  123.                     /* High byte of message. */
  124.  
  125.                 case mouseMovedMessage:
  126.                     DoIdleTasks(event);        /* Treat mouseMoved events like NULL events. */
  127.                     break;
  128.  
  129.                 case suspendResumeMessage:
  130.                         /* Suspend/resume is also an activate/deactivate. */
  131.                     gInBackground = !((event->message) & resumeFlag);
  132.                     CTEConvertClipboard((event->message) & convertClipboardFlag, !gInBackground);
  133.                     DoActivate(FrontWindow());
  134.                     HiliteWindows();
  135.                     break;
  136.             }
  137.             break;
  138.  
  139.         case diskEvt:
  140.             gCursorPtr = nil;            /* Force recalculation of the cursor. */
  141.             if (HiWord(event->message) != noErr) {
  142.                 SetPt(&pt, kDILeft, kDITop);
  143.                 err = DIBadMount(pt, event->message);
  144.             }        /* It is not a bad idea to at least call DIBadMount in response to */
  145.             break;    /* a diskEvt, so that the user can format a floppy. */
  146.     }
  147.  
  148.     DoCursor();
  149.     DoAdjustMenus();
  150. }
  151.  
  152.  
  153.  
  154. /*****************************************************************************/
  155.  
  156.  
  157.  
  158. /* •• Called by DTS.Lib..framework. •• */
  159.  
  160. /* This is called when a window is activated or deactivated. */
  161.  
  162. void    DoActivate(WindowPtr window)
  163. {
  164.     RgnHandle    rgn, oldClip;
  165.     Point        pt;
  166.  
  167.     NotifyCancel();
  168.  
  169.     if (IsAppWindow(window)) {
  170.  
  171.         SetPort(window);
  172.         DoCtlActivate(window);
  173.         DoDrawFrame(window, true);            /* Redraw frame for new activate state. */
  174.  
  175.         CopyRgn(((WindowPeek)window)->contRgn, rgn = NewRgn());
  176.         DiffRgn(rgn, ((WindowPeek)window)->updateRgn, rgn);
  177.             /* Don't draw any part that's already destined to draw due to an update event.
  178.             ** This prevents part of an exposed window from drawing twice, and thus avoids
  179.             ** flickering. */
  180.  
  181.         BeginContent(window);
  182.  
  183.         pt.h = pt.v = 0;
  184.         GlobalToLocal(&pt);
  185.         OffsetRgn(rgn, pt.h, pt.v);
  186.             /* This offset may seem wrong, since the origin may not be 0,0.  It is actually correct,
  187.             ** since at the time of the GlobalToLocal, the port's origin was set to the content origin.
  188.             ** A clearer way to look at this is in two steps:
  189.             ** 1) With the port's origin at 0,0, do a GlobalToLocal on 0,0, and then offset the new clip
  190.             **    by that amount.
  191.             ** 2) Once the port's origin is set correctly, the new clip needs to be offset again, based
  192.             **    on the origin value.  (The clipRgn travels with the origin, unlike the visRgn.)
  193.             ** The above is what automatically happens when you do the GlobalToLocal of 0,0 on the
  194.             ** correct origin.  Offsets are additive.  One step -- no muss, no fuss. */
  195.  
  196.         GetClip(oldClip = NewRgn());
  197.         SetClip(rgn);
  198.         DoDrawControls(window, true);        /* Redraw content scrollbars for new activate state. */
  199.         SetClip(oldClip);
  200.         DisposeRgn(oldClip);
  201.         DisposeRgn(rgn);
  202.  
  203.         EndContent(window);
  204.     }
  205. }
  206.  
  207.  
  208.  
  209.